import { queryDistrictList, queryFaultTypeList, queryFaultRepairList, queryOverTimeList, queryMaintainList,
  actionDistrictExport, actionFaultTypeExport, actionFaultRepairExport, actionOverTimeExport, actionMaintainExport

} from '../services/statistics';

export default {
  namespace: 'statistics',

  state: {
    resdata: {
      list: [],
      pagination: {},
    },
  },

  effects: {
    *fetch_statistics_district({ payload }, { call, put }) {
      const response =yield call(queryDistrictList, payload);
      response &&  (
        yield put({
          type: 'appendData',
          payload:response.data,
        })
      )
    },

    *fetch_statistics_falut({ payload }, { call, put }) {
      const response =yield call(queryFaultTypeList, payload);
      response &&  (
        yield put({
          type: 'appendData',
          payload:response.data,
        })
      )
    },

    *fetch_statistics_repair({ payload }, { call, put }) {
      const response =yield call(queryFaultRepairList, payload);
      response &&  (
        yield put({
          type: 'appendData',
          payload:response.data,
        })
      )
    },

    *fetch_statistics_overtime({ payload }, { call, put }) {
      const response =yield call(queryOverTimeList, payload);
      response &&  (
        yield put({
          type: 'appendData',
          payload:response.data,
        })
      )
    },

    *fetch_statistics_maintain({ payload }, { call, put }) {
      const response =yield call(queryMaintainList, payload);
      response &&  (
        yield put({
          type: 'appendData',
          payload:response.data,
        })
      )
    },


    // 文件导出
    *action_district_export({ payload }, { call, put }) {
      const response = yield call(actionDistrictExport, payload);
    },

    *action_faultype_export({ payload }, { call, put }) {
      const response = yield call(actionFaultTypeExport, payload);
    },
    *action_faultrepair_export({ payload }, { call, put }) {
      const response = yield call(actionFaultRepairExport, payload);
    },
    *action_overtime_export({ payload }, { call, put }) {
      const response = yield call(actionOverTimeExport, payload);
    },
    *action_maintain_export({ payload }, { call, put }) {
      const response = yield call(actionMaintainExport, payload);
    },

  },

  reducers: {

    appendChartsData(state, action) {
      return {
        ...state,
        chartsData: action.payload,
      };
    },

    appendData(state, action) {
      return {
        ...state,
        resdata: action.payload,
      };
    },

    // changeLoading(state, action) {
    //   return {
    //     ...state,
    //     loading: {
    //       ...state.loading,
    //       ...action.payload,
    //     },
    //   };
    // },

    appendClearState(state, action) {
      return {
        ...state,
        resdata:{
          list: [],
        },
      };
    },
  },
};

